package com.fare.fdc.action;

import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.application.analyse.AirCompanyChannelContrastApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.application.plane.flight.FlightInfoApplication;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.util.I18nUtil;
import com.fare.taluo.vo.core.FlightInfoVO;
import com.fare.taluo.vo.core.SourceEntityVO;
import com.fare.util.PriceUtil;

/**
 * @author spring.华 
 * 渠道走势对比
 */
@Controller("channelContrastAction")
@Scope("prototype")
public class ChannelContrastAction extends BaseFdcAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 8914871195674136087L;
	
	private String language;
	private String fromCity;
	private String fromCityCode;
	private String toCity;
	private String toCityCode;
	private String flightNo;
	private String flightStartDate;
	private String flightEndDate;
	private Integer futureDay;//未来天数
	private String[] periods;//出发时段,AMPN
	private Integer selfStartPeriods;//自定义出发时段（开始）(小时)
	private Integer selfEndPeriods;//自定义出发时段（结束）(小时)
	private String airCompanyHbaseKey;//官网habseKey
	private String comparedChannelHbaseKey;//渠道habseKey
	private List<SourceEntityVO> crawlCompanys;//所有的当前处于抓取状态的公司
	private List<SourceEntityVO> crawlChannels;//所有的当前处于抓取状态的渠道
	@Resource(name = "flightInfoApplication")
	private FlightInfoApplication flightInfoApplication;
	@Resource(name="sourceApplication")
	private SourceApplication sourceApplication;
	@Resource(name="airCompanyChannelContrastApplicationImpl")
	private AirCompanyChannelContrastApplication airCompanyChannelContrastApplication;
	
	private String priceType;
	private String airCompanyCabin;
	private String comparedCabins;
	/**
	 * 页面动态加载航班号的
	 * 
	 * @throws Exception
	 */
	public void getFlightNo() throws Exception{
		List<FlightInfoVO> fs=airCompanyChannelContrastApplication.getFlights(airCompanyHbaseKey, fromCity, toCity);
		fs=PriceUtil.generateOnly(fs);//排重
		super.toJSONOut(com.fare.taluo.util.JsonUtil.toJson(fs));
	}
	/**
	 * 跳转到jsp
	 * @return
	 * @throws Exception
	 */
	public String toView() throws Exception{
		returnPageURL = "/fare/fdc/qdzsdb.jsp";
		this.crawlCompanys=sourceApplication.findCrawlAirCompanys();
		this.crawlChannels=sourceApplication.findCrawlChannel();
		Locale locale = super.getLocale();
		I18nUtil.sourceConvert2I18N(crawlCompanys, locale);
		I18nUtil.sourceConvert2I18N(crawlChannels, locale);
		request.setAttribute("maxDate", DateUtils.getDateAfter(29));//目前只支持30天的数据 
		language=locale.toString();
		if(!language.equalsIgnoreCase("zh_CN") && !language.equalsIgnoreCase("en_US")){
			language="other";
		}
		return "dispatcher";
	}
	
	
	public void analyse()throws Exception{
		try {
			Locale locale = super.getLocale();
			String xml=airCompanyChannelContrastApplication.getFusionChartsXMLStr(
					fromCity, toCity,fromCityCode,toCityCode, 
					flightNo, flightStartDate, flightEndDate, futureDay,
					periods, selfStartPeriods, selfEndPeriods, 
					airCompanyHbaseKey, comparedChannelHbaseKey, priceType,locale);
			super.toJSONOut(xml);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		
	}
	
	
	public void analyseCabin(){
		try {
			Locale locale = super.getLocale();
			String jsonStr=airCompanyChannelContrastApplication.getFusionChartsXMLStrCabin(
					fromCity, toCity, fromCityCode, toCityCode, flightStartDate, flightEndDate, airCompanyCabin, comparedCabins, priceType,locale);
			super.toJSONOut(jsonStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	
	}

	public SourceApplication getSourceApplication() {
		return sourceApplication;
	}
	public void setSourceApplication(SourceApplication sourceApplication) {
		this.sourceApplication = sourceApplication;
	}
	public List<SourceEntityVO> getCrawlCompanys() {
		return crawlCompanys;
	}
	public void setCrawlCompanys(List<SourceEntityVO> crawlCompanys) {
		this.crawlCompanys = crawlCompanys;
	}
	public List<SourceEntityVO> getCrawlChannels() {
		return crawlChannels;
	}
	public void setCrawlChannels(List<SourceEntityVO> crawlChannels) {
		this.crawlChannels = crawlChannels;
	}
	
	
	public String getFlightStartDate() {
		return flightStartDate;
	}
	public void setFlightStartDate(String flightStartDate) {
		this.flightStartDate = flightStartDate;
	}
	public String getFlightEndDate() {
		return flightEndDate;
	}
	public void setFlightEndDate(String flightEndDate) {
		this.flightEndDate = flightEndDate;
	}
	public Integer getFutureDay() {
		return futureDay;
	}
	public void setFutureDay(Integer futureDay) {
		this.futureDay = futureDay;
	}
	public String[] getPeriods() {
		return periods;
	}
	public void setPeriods(String[] periods) {
		this.periods = periods;
	}
	public Integer getSelfStartPeriods() {
		return selfStartPeriods;
	}
	public void setSelfStartPeriods(Integer selfStartPeriods) {
		this.selfStartPeriods = selfStartPeriods;
	}
	public Integer getSelfEndPeriods() {
		return selfEndPeriods;
	}
	public void setSelfEndPeriods(Integer selfEndPeriods) {
		this.selfEndPeriods = selfEndPeriods;
	}
	public String getAirCompanyHbaseKey() {
		return airCompanyHbaseKey;
	}
	public void setAirCompanyHbaseKey(String airCompanyHbaseKey) {
		this.airCompanyHbaseKey = airCompanyHbaseKey;
	}
	public String getComparedChannelHbaseKey() {
		return comparedChannelHbaseKey;
	}
	public void setComparedChannelHbaseKey(String comparedChannelHbaseKey) {
		this.comparedChannelHbaseKey = comparedChannelHbaseKey;
	}
	public FlightInfoApplication getFlightInfoApplication() {
		return flightInfoApplication;
	}
	public void setFlightInfoApplication(FlightInfoApplication flightInfoApplication) {
		this.flightInfoApplication = flightInfoApplication;
	}
	public AirCompanyChannelContrastApplication getAirCompanyChannelContrastApplication() {
		return airCompanyChannelContrastApplication;
	}
	public void setAirCompanyChannelContrastApplication(
			AirCompanyChannelContrastApplication airCompanyChannelContrastApplication) {
		this.airCompanyChannelContrastApplication = airCompanyChannelContrastApplication;
	}
	public void setFlightNo(String flightNo) {
		this.flightNo = flightNo;
	}
	public String getFromCity() {
		return fromCity;
	}
	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}
	public String getToCity() {
		return toCity;
	}
	public void setToCity(String toCity) {
		this.toCity = toCity;
	}
	public String getFromCityCode() {
		return fromCityCode;
	}
	public void setFromCityCode(String fromCityCode) {
		this.fromCityCode = fromCityCode;
	}
	public String getToCityCode() {
		return toCityCode;
	}
	public void setToCityCode(String toCityCode) {
		this.toCityCode = toCityCode;
	}
	public String getPriceType() {
		return priceType;
	}
	public void setPriceType(String priceType) {
		this.priceType = priceType;
	}
	public String getAirCompanyCabin() {
		return airCompanyCabin;
	}
	public void setAirCompanyCabin(String airCompanyCabin) {
		this.airCompanyCabin = airCompanyCabin;
	}
	public String getComparedCabins() {
		return comparedCabins;
	}
	public void setComparedCabins(String comparedCabins) {
		this.comparedCabins = comparedCabins;
	}
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
	

}
